/*
 * Room.java
 *
 * Created on August 30, 2008, 11:05 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Project.bussiness;

import Project.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.jar.Pack200;

/**
 *
 * @author Hao Hao
 */
public class Room {
    
    /** Creates a new instance of Room */
private int RoomID;
private String Name;
private int Price;

    public int getRoomID() {
        return RoomID;
    }

    public void setRoomID(int RoomID) {
        this.RoomID = RoomID;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public int getPrice() {
        return Price;
    }

    public void setPrice(int Price) {
        this.Price = Price;
    }

    public static Vector getAllRoom() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetAllRooms");
            while(rs.next()){
                Room r = new Room();
                r.setRoomID(rs.getInt(1));
                r.setName(rs.getString(2));
                r.setPrice(rs.getInt(3));
                v.add(r);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }   
    
    public static Vector getRoomById(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            ResultSet rs = DBHelper.executeQuery("spSearchRoomById", paramList);
            
            while(rs.next()){
                Room r = new Room();
                r.setRoomID(rs.getInt(1));
                r.setName(rs.getString(2));
                r.setPrice(rs.getInt(3));
                v.add(r);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     
    
    public static Vector getRoomByName(String name) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(name);
            ResultSet rs = DBHelper.executeQuery("spSearchRoomById", paramList);           
            while(rs.next()){
                Room r = new Room();
                r.setRoomID(rs.getInt(1));
                r.setName(rs.getString(2));
                r.setPrice(rs.getInt(3));
                v.add(r);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     

    public static int insertRoom(Room r) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(r.Name);
            paramList.add(r.Price);
            i=DBHelper.executeUpdate("spInsertRoom",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }              

    public static int updateRoom(int id, Room r) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add((Integer)id);
            paramList.add(r.Name);
            paramList.add(r.Price);
            i=DBHelper.executeUpdate("spUpdateRoom",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }              

    public static int deleteRoom(int id) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add((Integer)id);
            i=DBHelper.executeUpdate("spDeleteRoom",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }              

}
